﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.SalesManagement;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sell.Api.Write.Application.Command.PhrasesCommand;

namespace Sell.Api.Write.Controllers.Phrases
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PhrasesController : ControllerBase
    {
        private readonly IMediator mediator;
        public PhrasesController(IMediator _mediator)
        {
            mediator = _mediator;
        }
        /// <summary>
        /// 添加销售合同
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> PhrasesAdd([FromBody] PhrasesAddCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
        /// <summary>
        /// 销售合同删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> PhrasesDel([FromQuery]PhrasesDelCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 销售合同修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> PhrasesUpdate([FromBody] PhrasesUpdateCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改销售合同审核状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> PhrasesUpdateReviewStatus([FromBody] PhrasesUpdateReviewStatusCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
    }
}
